# -*- coding: utf-8 -*-

import mod.server.extraServerApi as serverApi

from enchantBase import EnchantBase

comp = serverApi.GetEngineCompFactory()
levelId = serverApi.GetLevelId()


class Charging(EnchantBase):
    def __init__(self, system, playerId, enchantData, levels):
        EnchantBase.__init__(self, system, playerId, enchantData, levels)
        self.charged = False
        self.timer = 0
        pass

    def isArmorEnchant(self):
        return False

    def onEnter(self):
        self.charged = False
        self.timer = 0
        self.mSystem.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), 'StartDestroyBlockServerEvent', self, self.charging)
        pass

    def onExit(self):
        self.mSystem.UnListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), 'StartDestroyBlockServerEvent', self, self.charging)
        pass

    def second(self):
        if not self.charged:
            self.timer += 1
        enchant_level = self.enchantData[1]
        if self.timer >= 6 - enchant_level:
            self.charged = True
            comp.CreateGame(self.playerId).SetOneTipMessage(self.playerId, "§e充能完毕！")
        pass

    def charging(self, args):
        if self.charged:
            # 当充能满时，提供急迫II效果。
            comp_effect = comp.CreateEffect(self.playerId)
            comp_effect.AddEffectToEntity('haste', 3, 1, True)
            self.charged = False
        pass
